/*
 * lcd_display.h
 *
 *  Created on: 2024年9月16日
 *      Author: LeiWang
 */

#ifndef OLCD_DRIVER_H
#define OLCD_DRIVER_H

#include "main.h"
#include "gpio.h"
#include "spi.h"

#define LCD_SPI_HANDLE hspi1        // 定义使用的SPI总线

#define USE_HORIZONTAL 2

//-------------设置lcd分辨率--------------------
#define LCD_WIDTH   320
#define LCD_HEIGHT  170

typedef enum{
    LCD_CMD = 0,    // lcd写命令
    LCD_DATA        // lcd写数据
}LCD_WR_MODE;

//-------------定义GPIO端口---------------------

#define LCD_RES_GPIO    GPIOC
#define LCD_RES_PIN     GPIO_PIN_5
#define LCD_DC_GPIO     GPIOB
#define LCD_DC_PIN      GPIO_PIN_1
#define LCD_CS_GPIO     GPIOB
#define LCD_CS_PIN      GPIO_PIN_2

//-------------定义LCD接口----------------------

#define lcd_res_clr()   HAL_GPIO_WritePin(LCD_RES_GPIO,LCD_RES_PIN,GPIO_PIN_RESET)
#define lcd_res_set()   HAL_GPIO_WritePin(LCD_RES_GPIO,LCD_RES_PIN,GPIO_PIN_SET)
#define lcd_dc_clr()    HAL_GPIO_WritePin(LCD_DC_GPIO,LCD_DC_PIN,GPIO_PIN_RESET)
#define lcd_dc_set()    HAL_GPIO_WritePin(LCD_DC_GPIO,LCD_DC_PIN,GPIO_PIN_SET)
#define lcd_cs_clr()    HAL_GPIO_WritePin(LCD_CS_GPIO,LCD_CS_PIN,GPIO_PIN_RESET)
#define lcd_cs_set()    HAL_GPIO_WritePin(LCD_CS_GPIO,LCD_CS_PIN,GPIO_PIN_SET)

//-------------LCD驱动函数----------------------

void lcd_spi_write(uint8_t data);
void lcd_write_cmd(uint8_t cmd);
void lcd_write_data8(uint16_t dat);
void lcd_write_data(uint16_t dat);
void lcd_address_set(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1);
void lcd_init();
void lcd_draw_point(uint16_t x, uint16_t y, uint16_t color);
void lcd_fill_screen(uint16_t color);
void lcd_draw_line(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t color);
void lcd_draw_rectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,uint16_t color);
void lcd_draw_circle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color);
void lcd_show_char(uint16_t x, uint16_t y, uint8_t ch, uint16_t text_color, uint16_t bg_color,uint8_t size,uint8_t mode);
void lcd_show_string(uint16_t x,uint16_t y,const uint8_t *p,uint16_t fc,uint16_t bc,uint8_t sizey,uint8_t mode);
void lcd_show_int(uint16_t x,uint16_t y,uint16_t num,uint8_t len,uint16_t fc,uint16_t bc,uint8_t sizey);
void lcd_show_float(uint16_t x,uint16_t y,float num,uint8_t len,uint16_t fc,uint16_t bc,uint8_t sizey);
void lcd_show_chinese();
void lcd_show_picture(uint16_t x0, uint16_t y0, uint16_t width, uint16_t height, const uint8_t pic[]);

//-------------定义画笔颜色(RGB565)---------------------

#define WHITE           0xFFFF
#define BLACK           0x0000
#define BLUE            0x001F
#define BRED            0XF81F
#define GRED            0XFFE0
#define GBLUE           0X07FF
#define RED             0xF800
#define MAGENTA         0xF81F
#define GREEN           0x07E0
#define CYAN            0x7FFF
#define YELLOW          0xFFE0
#define BROWN           0XBC40  //棕色
#define BRRED           0XFC07  //棕红色
#define GRAY            0X8430  //灰色
#define DARKBLUE        0X01CF  //深蓝色
#define LIGHTBLUE       0X7D7C  //浅蓝色  
#define GRAYBLUE        0X5458  //灰蓝色
#define LIGHTGREEN      0X841F  //浅绿色
#define LGRAY           0XC618  //浅灰色(PANNEL),窗体背景色
#define LGRAYBLUE       0XA651  //浅灰蓝色(中间层颜色)
#define LBBLUE          0X2B12  //浅棕蓝色(选择条目的反色)

#endif